/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file types.h
 * @brief commont types header for project 
 * @author taco [tacoee@gmail.com]
 * @version 
 * @date 2010-09-08
 */
#ifndef TYPES_H_
#define TYPES_H_

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define THREAD_SUCESS	(void *) (-1)
#define THREAD_FAIL		(void *) (0)

typedef enum _Ret {
	RET_REMOVE,
	RET_CONTINUE,
	RET_FOUND,
	RET_EOF,
	RET_NEXT,
	RET_QUIT,
	RET_EXIST,
	RET_AGAIN,
	RET_IGNORED,
	RET_NO_TARGET,
	RET_NOT_FOUND,
	RET_OUT_OF_SPACE,
	RET_FAIL = -1,
	RET_OK = 0
} Ret;

typedef enum _SockStat {
	READ_HEADER,
	ONE_CR,
	ONE_LF,
	TWO_CR,
	BODY_READ,
	BODY_WRITE,
	WRITE,
	PIPE_READ,
	PIPE_WRITE,
	DONE,
	DEAD              
} SockStat;


#define return_if_fail(p) if(!(p)) { printf("%s:%d "#p" failed.\n", __func__, __LINE__); return;}
#define return_val_if_fail(p, val) if(!(p)) {printf("%s:%d "#p" failed.\n", __func__, __LINE__); return (val);}

static FILE *__log_debug;
#define WP_DEBUG
#ifdef WP_DEBUG
#define dbg_log(fmt, args...) do {  if(__log_debug == NULL) __log_debug = stdout; \
						fprintf(__log_debug, "Debug %s->%d: "fmt"\n", __func__, __LINE__, ##args); \
						fflush(__log_debug);													\
						} while(0)
#else
#define dbg(fmt, args...)
#endif
static FILE *__log_error;
#define err_log(fmt, args...) do {	if(__log_error == NULL) __log_error = stderr; \
						fprintf(__log_error, "Error %s->%d: " fmt"\n", __func__, __LINE__, ##args); \
						fflush(__log_error); \
						} while(0)

#define set_log_debug(file)		do {	\
			__log_debug = #file;		\
		} while(0)		
#define set_log_error(file)		do {	\
			__log_error = file;			\
		} while(0)

#endif /*TYPES_H_*/
